package com.chwn.curiousdiary.provider;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by Myshikin on 2017/4/27.
 */

public class StoryDB extends SQLiteOpenHelper {

    public static final  String  DATABASENAME = "story.db";
    private static final int     VERSION      = 2;
    private static       StoryDB sInstance    = null;

    private final Context mContext;

    private StoryDB(Context context) {
        super(context, DATABASENAME, null, VERSION);

        mContext = context;
    }

    public static StoryDB getInstance(Context context) {
        if (sInstance == null) {
            synchronized (StoryDB.class) {
                if (sInstance == null) {
                    sInstance = new StoryDB(context.getApplicationContext());
                }
            }
        }
        return sInstance;
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        DownloadStoryStore.getInstance(mContext).onCreate(sqLiteDatabase);
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {
        DownloadStoryStore.getInstance(mContext).onUpgrade(sqLiteDatabase, oldVersion, newVersion);
    }
}
